<?php

namespace App\Http\Controllers;

use App\Model\Logic\LoginLogic;
use Illuminate\Http\Request;

class LoginController extends Controller
{
    private $logic;
    public function __construct(LoginLogic $logic)
    {
        $this->logic = $logic;
    }
    //登录界面
    public function index(){
        return view('login');
    }
    // 登录处理
    public function login(Request $request){
        // 登录验证
        $this->validate($request,[
            'username' => 'required'
        ]);
        // 逻辑层处理
        $bool = $this->logic->checkLogin($request->all());
        if($bool){
            return redirect(route('index'))->with('success','登录成功');
        }
        return redirect()->back()->with('error','登录失败');
    }
}
